package cn.keduox.dao.impl;

import cn.keduox.entity.HotBook;
import cn.keduox.entity.HotBookType;
import cn.keduox.entity.PageBean;
import cn.keduox.utils.JDBCUtils;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;

/**
 * User: Yongman
 * Date: 2018/1/2
 */
public class HotBookDaoImpl extends BaseDaoImpl<HotBook,PageBean>{
    /**
     * 查询总数
     * @return
     */
    public int queryCount(String type){
//        声明
        Connection con = null;
        PreparedStatement ps = null;
        ResultSet rs = null;
        try {
//            获取连接
            con = JDBCUtils.getConnection();
//            查询总条数
            String sql = "select count(1) from `hot_book` where type_id = ?";
            ps = con.prepareStatement(sql);
            JDBCUtils.setObject(ps,type);
//            执行查询
            rs = ps.executeQuery();
            while (rs.next()){
//                获取并返回
                int count = rs.getInt("count(1)");
                return count;
            }
        }catch (Exception e){
            e.printStackTrace();
        }finally {
            JDBCUtils.close(con,ps,rs);
        }
        return 1;
    }
}
